import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { AiDutyStatusRecordsApi } from '#/api/moxi/aiDutyStatus';
import Dayjs from 'dayjs';

import {
  getRangePickerDefaultProps,
} from '#/utils';

/** 新增/修改的表单 */

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'userid',
      label: '离岗员工ID',
      component: 'Input',
      componentProps: {
        placeholder: '请输入离岗员工ID',
        allowClear: true,
      },
    },
    {
      fieldName: 'times',
      label: '离岗时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns<T = AiDutyStatusRecordsApi.AiDutyStatusRecords>(
  onStatusChange?: (
    newStatus: number,
    row: T,
  ) => PromiseLike<boolean | undefined>,
): VxeTableGridOptions['columns'] {
  return [
    {
      field: 'id',
      title: '序号',
    },
    {
        field: 'empeId',
        title: '离岗编号',
      },
    {
      field: 'userid',
      title: '离岗员工ID',
    },
    {
      field: 'name',
      title: '姓名',
      formatter: ({ row }) => {
        return  row?.employee?.name;
      }
    }, 
    {
        field: 'deptNames',
        title: '部门',
        formatter: ({ row }) => {
            return row?.employee?.deptNames?.split(',').pop()?.trim() || '';
        }
    },
    {
      field: 'type', 
      title: '状态',//1在岗2离岗3离岗误报
      formatter: ({ cellValue }) => {
        const statusMap = {
          1: '在岗',
          2: '离岗',
        //   3: '离岗误报'
        };
        return statusMap[cellValue as keyof typeof statusMap] || '未知状态';
      },
    },
    {
        field: 'startTime',
        title: '离岗时间',
        formatter: ({ cellValue }) => {
          return cellValue?Dayjs(cellValue).format('YYYY-MM-DD') : '';
        }
    },
    {
        field: 'duration',
        title: '离岗时长min',
    },
    {
        field: 'camera',
        title: '离岗摄像头',
        formatter: ({ cellValue }) => {
          return cellValue?.nickname;
        }
    },

    {
      title: '操作',
      width: 180,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
